<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            按箱撤回
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">发货单号</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="consignment" value="" disabled="true">
                    </div>
                </div>
            </li>

            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">箱号</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请扫描箱号" id="boxnum" value="" onclick="getIdSelector();">
                    </div>
                </div>
            </li>

            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">物料号</div>
                    <input type="text" class="aui-input" id="mrlCode">
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">批次号</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="lotCode">
                    </div>
                </div>
            </li>

            </li>
        </ul>
        <div style="width:100%;margin-top:2%;"></div>
        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info" style="margin-left:5%;width:40%" onclick="search()">查询</div>
        <div class="aui-btn aui-btn-info" style="margin-left:10%; width:40%" onclick="deleteHand()">撤回</div>
        <div
            style="background-color:white; width: 100%;margin-top:2%;white-space: nowrap;overflow-x: auto;-webkit-overflow-scrolling:touch;">

            <table class="table" style='width:1000px;' id="table1">
                <tbody style="display:block">
                    <tr
                        style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 15px;font-weight: bold;">
                        <td algin='center' style="width:40px;"></td>
                        <td algin='center' style="width:50px;">序号</td>
                        <td algin='center' style="width:133px;;">箱号</td>
                        <td algin='center' style="width:133px;;">托号</td>
                        <td algin='center' style="width:152px;">物料编码</td>
                        <td algin='center' style="width:102px;">物料名称</td>
                        <td algin='center' style="width:80px;">数量</td>
                        <td algin='center' style="width:146px;">批次号</td>
                    </tr>
                </tbody>
            </table>
            <table class="table" style='width:1000px;' id="table">
                <tbody id="tbodyHtml" style="display: block;height: 300px;overflow-y: scroll;">
                </tbody>
            </table>
        </div>
    </div>
    <div>
        <div style="height:60px;"></div>
        <footer class="aui-bar aui-bar-tab" id="footer">
            <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
                <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
            </div>
        </footer>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var scanRule = ""; //条码解析规则

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //初始化查询仓库下拉框
    apiready = function () {
        $("#boxnum").focus();
        $("#boxnum").select();
        idSelector = "boxnum";

        var consignment = api.pageParam.consignment;
        $("#consignment").val(consignment);
        search()

    }

    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {
            //1：箱号
            if (idSelector == 'boxnum') {
                //条码解析+自栋绑定
                tmSplit(ret);
               // $("#boxnum").val(ret);
               // search()
            }
        });
    }

   //条码解析
    function tmSplit(tm) {
        var arr = tm.split(",");
        //物料号
        //$("#mrlCode").val(arr[1]);
        //数量
        //$("#qty").val(arr[2]);
        //$("#lotCode").val(arr[3]);
        //$("#tmID").val(arr[4]);
        //箱号
        $("#boxnum").val(arr[9]);
        //条码
       // $("#tm").val(tm);
        //查询
        search()
    }


    //箱号监听回车事件
    $("#boxnum").on('keypress', function (e) {
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            //条码解析+保存
            tmSplit(tm);
           // search()
        }
    });

    //根据发货单查询表格数据
    function search() {
        var consignment = $("#consignment").val();
        var boxnum = $("#boxnum").val();
        var mrlCode = $("#mrlCode").val();
        var lotCode = $("#lotCode").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getBangbingBoxnum";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                consignment: consignment,
                boxnum: boxnum,
                mrlCode: mrlCode,
                lotCode: lotCode,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {

                    var list = eval(myobj.list);
                    var html = "";
                    //发货单明细数据存在
                    if (list.length > 0) {
                        //遍历
                        for (var i = 0; i < list.length; i++) {
                            html += "<tr style='text-align: center;color: black;font-size: 12px;background-color: #F5F5F5;'>";
                            html += "<td style='width:40px;'><input name='sub' type='checkbox' /></td>";
                            html += "<td name='seqNo' style='width:50px;'>" + (i + 1) + "</td>";
                            html += "<td name='boxnum' style='width:130px;'>" + list[i].boxnum + "</td>";
                            html += "<td name='tuonum' style='width:130px;'>" + (list[i].ctBarcode == null ? "" : list[i].ctBarcode) + "</td>";
                            html += "<td name='mrlCode' style='width:150px;'>" + list[i].sitmCode + "</td>";
                            html += "<td name='mrlName' style='width:100px;'>" + list[i].sitmNode + "</td>";
                            html += "<td name='qty' style='width:80px;'>" + list[i].qyt + "</td>";
                            html += "<td name='lotCode' style='width:150px;'>" + (list[i].lotCode == null ? "" : list[i].lotCode) + "</td>";
                            html += "<td name='id' style='display:none;'>" + list[i].id + "</td>";
                            html += "</tr>";
                        }

                    } else {
                        $("#boxnum").val("");
                        $("#boxnum").focus();
                        $("#boxnum").select();
                        idSelector = "boxnum";
                    }

                    $api.html($api.byId("tbodyHtml"), html);

                    //失败，存在没有订单数据
                } else if (myobj.code == "1") {
                    $("#consignment").select();
                    idSelector = "consignment";
                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //删除选中绑定
    function deleteHand() {
        var consignment = $("#consignment").val();
        //选中数据
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        check.each(function() {
            count++;
        });
        //选中行不为1
        if (count == 0) {
            api.toast({
                msg: '请选择至少一条数据！',
                duration: 3000
            });
            return;
        }
        var list = [];

        check.each(function() { //遍历
            var row = $(this).parent("td").parent("tr");
            var boxnum = row.find("[name='boxnum']").html();

            list.push({
                "boxnum": boxnum,
            });
        });
        api.showProgress({
            title: '删除中...',
        });

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/uwmSFKDeleteByBoxnum";
        var params = new Object();
        var data = {
            values: {
                consignment: consignment, //发货单号
                list: JSON.stringify(list),
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    api.hideProgress();
                    api.toast({
                        msg: '删除成功',
                        duration: 5000
                    });
                    // $("#boxnum").val("");
                    // $("#mrlCode").val("");
                    search();

                    //失败
                } else if (myobj.code == '1') {
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 5000
                    });
                }
            }
        });
    }




    //返回按钮 uwmSFKScanCodeBinding
    function closeWin() {
        api.closeWin({});
        api.execScript({
            name: 'uwmSFKScanCodeBinding',
            script: 'search();'
        });
    }
</script>

</html>